﻿<?php
	$this->Paginator->options(array('url' => array('admin' => true, 'plugin' => null, 'controller' => 'categories', 'action' => 'index')));
?>
<div class="categories index">
	<h2><?php echo 'Categories'; ?></h2>
	<table cellpadding="0" cellspacing="0">
	<tr>
		<th>
		<?php
			echo $this->Paginator->sort(
				'ID',
				'id'
			);
		?>
		</th>
		<!--
		<th>
		<?php
			echo $this->Paginator->sort(
				'Active',
				'is_active'
			);
		?>
		</th>
		-->
		<th>
		<?php
			echo $this->Paginator->sort(
				'Parent',
				'parent_id'
			);
		?>
		</th>
		<th>
		<?php
			echo $this->Paginator->sort(
				'Name',
				'name'
			);
		?>
		</th>
		<th class="actions"><?php echo 'Actions'; ?></th>
	</tr>
	<?php
	$i = 0;
	foreach ($categories as $category) {
		$class = null;
		if ($i++ % 2 == 0) {
			$class = ' class="altrow"';
		}
	?>
		<tr<?php echo $class;?>>
			<td>
				<?php echo $category['Category']['id']; ?>
			</td>
			<!--
			<td>
				<?php
				if($category['Category']['is_active']) {
					echo '<span style="color: green">'.'да'.'</span>';
				} else {
					echo '<span style="color: red">'.'не'.'</span>';
				}
				?>
			</td>
			-->
			<td>
				<?php
					echo ' / ';
					if(!empty($category["Category"]["parents"])) {
						for($j = 0, $parentsSize = (count($category["Category"]["parents"]) - 1); $j < $parentsSize; $j++) {
							echo $this->Html->link($category["Category"]["parents"][$j]["Category"]["name"], array('admin' => true, 'plugin' => null, 'controller' => 'categories', 'action' => 'edit', $category["Category"]["parents"][$j]["Category"]["id"]));
							echo ' / ';
						}
					}
				?>
			</td>
			<td>
				<?php echo htmlspecialchars($category['Category']['name']); ?>
			</td>
			<td class="actions">
				<?php echo $this->Html->link('Edit', array('admin' => true, 'plugin' => null, 'controller' => 'categories', 'action' => 'edit', $category['Category']['id'])); ?>
				<?php echo $this->Html->link('Delete', array('admin' => true, 'plugin' => null, 'controller' => 'categories', 'action' => 'delete', $category['Category']['id']), null, sprintf('Сигурни ли сте, че искате да изтриете # %s?', $category['Category']['id'])); ?>
			</td>
		</tr>
	<?php } ?>
	</table>
	<p>
	<?php
	echo $this->Paginator->counter(array(
	'format' => 'Страницa %page% от %pages%, показваща %current% записа от %count% общо, започваща от запис %start%, свършваща на запис %end%'
	));
	?></p>
	<div class="paging">
		<?php echo $this->Paginator->prev('<< '.'предишна', array(), null, array('class'=>'disabled'));?>
	 | 	<?php echo $this->Paginator->numbers();?>
	 |
		<?php echo $this->Paginator->next('следваща'.' >>', array(), null, array('class'=>'disabled'));?>
	</div>
</div>
<div class="actions">
	<h3><?php echo 'Действия:'; ?></h3>
	<ul>
		<li><?php echo $this->Html->link('Add', array('admin' => true, 'plugin' => null, 'controller' => 'categories', 'action' => 'add')); ?></li>
		<li><?php echo $this->Html->link('Add multiply', array('admin' => true, 'plugin' => null, 'controller' => 'categories', 'action' => 'addall')); ?></li>
		<li><?php echo $this->Html->link('Tree', array('admin' => true, 'plugin' => null, 'controller' => 'categories', 'action' => 'tree_view_manager')); ?></li>
	</ul>
</div>